const { regClass } = Laya;
import { StaticData } from "../../Data/StaticData";
import { ClickPointBase } from "./ClickPoint.generated";

@regClass()
export class ClickPoint extends ClickPointBase {
    id: number;
    actClick: (id: number) => void;
    type: NodeDifferentState;
    timeAutoToSelect: any;
    onAwake(): void {
        this.ViewDef.visible = false;
        this.ViewSelect.visible = false;
        this.NodeTips.visible = false;
        this.ImgSelect.color = "#FF0000";
        this.setType(NodeDifferentState.Def);
        this.BlockCube.visible = StaticData.showClickBlockCube;

        this.on(Laya.Event.CLICK, this, this.onClickMy);
    }

    setInfo(id: number, actClick: (id: number) => void = undefined): void {
        this.id = id;
        this.actClick = actClick;
    }

    setType(type: NodeDifferentState): void {
        this.ViewDef.visible = false;
        this.ViewSelect.visible = false;
        this.NodeTips.visible = false;
        switch (type) {
            case NodeDifferentState.Def:
                this.ViewDef.visible = true;
                break;
            case NodeDifferentState.Select:
                this.ViewSelect.visible = true;
                this.ImgSelect.color = "#FFFFFF";
                break;
            case NodeDifferentState.Tip:
                this.NodeTips.visible = true;
                break;
            case NodeDifferentState.success:
                Laya.timer.clear(this, this.autoToSelect);
                this.ViewSelect.visible = true;
                this.ImgSelect.color = "#00FF00";
                break;
            case NodeDifferentState.err:
                this.ViewSelect.visible = true;
                this.ImgSelect.color = "#FF0000";
                break;
        }
        this.type = type;
    }

    public aniToSelcet() {
        Laya.timer.clear(this, this.autoToSelect);
        Laya.timer.once(1000, this, this.autoToSelect)
    }
    private autoToSelect() {
        this.setType(NodeDifferentState.Select)
    }
    onDestroy(): void {
        Laya.timer.clear(this, this.autoToSelect);
    }
    onClickMy(): void {
        this.actClick?.(this.id);
    }

}
export enum NodeDifferentState {
    /** 初始 */
    Def,
    /** 选中 */
    Select,
    /** 正确 */
    success,
    /** 失败 */
    err,
    /** 提示 */
    Tip,
}